package com.example.common.util.encryption;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;

public class Encryption {
    // 生成 MD5 哈希值
    public static String md5(String input) throws NoSuchAlgorithmException {
        input = input + input;
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] hashBytes = md.digest(input.getBytes(StandardCharsets.UTF_8));
        for(int i=0; i<3; i++){
            hashBytes = md.digest(hashBytes);
        }
        return Base64.getEncoder().encodeToString(hashBytes);
    }
}
